package org.vy.dal.dao;

import org.vy.dal.QueryManager;

public class VyUserLoginDAO {
	
	private static final String FIND_BY_PK = "SELECT * FROM <TABLE> WHERE VY_ID = m_VyId";
	private static final String FIND_BY_USER_AND_PWD = "SELECT * FROM <TABLE> WHERE Username = m_Username and Password = m_Password";
	private static final String UPDATE = "UPDATE <TABLE> SET FIRST_NAME = m_Username WHERE VY_ID = m_VyId";
	private static final String INSERT = "INSERT INTO <TABLE> (VY_ID,FIRST_NAME) VALUES(m_VyId,m_Username)";
	
	public static VyUserLoginDO findByPK(String key) throws Exception {
		VyUserLoginDO dto = new VyUserLoginDO();
		dto.setVyid(key);
		dto = (VyUserLoginDO)QueryManager.executeQuery(dto, FIND_BY_PK);
		return dto;
	}

	public static VyUserLoginDO findByUserAndPwd(String name, String pwd) throws Exception {
		VyUserLoginDO dto = new VyUserLoginDO();
		dto.setUsername(name);
		dto.setPassword(pwd);
		dto = (VyUserLoginDO)QueryManager.executeQuery(dto, FIND_BY_USER_AND_PWD);
		return dto;
	}

	public static VyUserLoginDO insert(VyUserLoginDO dto) throws Exception {
		//TODO need implementation
		return dto;
	}

	public static VyUserLoginDO update(VyUserLoginDO dto) throws Exception {
		//TODO need implementation
		return dto;
	}
	
	public static void main(String[] s){
		try{
			VyUserLoginDO td = new VyUserLoginDO();
			td.setUsername("Raj");
			VyUserLoginDAO.insert(td);
			System.out.println("Seq Id = "+ td.getVyid());
			
			td.setUsername(null);
			td = VyUserLoginDAO.findByPK(td.getVyid());
			System.out.println("Query Name = "+ td.getUsername());
			
			td.setUsername("Gupta");
			td = VyUserLoginDAO.update(td);
			if(td != null)
				System.out.println("Update Name = "+ td.getUsername());
			else
				System.out.println("Update Failed");
			
		}catch(Exception e){
			e.printStackTrace();
		}
		
		
	}

}
